# -*- coding: utf-8 -*-

import itertools

def program(data):

    # Ellie骑紫色的车
    index = data[1].index('紫')
    if data[0][index] != 'Ellie':
        return -1

    #Rohan没有骑绿色的车
    index = data[1].index('绿')
    if data[0][index] == 'Rohan':
        return -1

    #骑蓝色车的人领先Fatma
    index = data[1].index('蓝')
    name_index = data[0].index('Fatma')
    if index - name_index >= 0:
        return -1

    #骑绿色车的人领先骑紫色车的人
    color_index1 = data[1].index('绿')
    color_index2 = data[1].index('紫')
    if color_index1 - color_index2 >= 0:
        return -1

    print('得到的排序是:')
    for item in data:
        print(item)
    print("第二名是")
    print(data[0][1])
    return 0

# permutations(p[,r]);   返回p中任意取r个元素做排列的元组的迭代器
name_list = list(itertools.permutations(['Mike', 'Ellie', 'Rohan', 'Fatma'], 4))
color_list = list(itertools.permutations(['红', '紫', '蓝', '绿'], 4))

name_list_handle = []
color_list_handle = []

# 先筛选一轮
for country in name_list:
    country = list(country)
    if country[0] != 'Mike' and country[3] != 'Mike' and country[0] != 'Ellie' and country[3] != 'Ellie':
        name_list_handle.append(country)

for i in range(24):
    color_list_handle.append(list(color_list[i]))

for name in name_list_handle:
    for color in color_list_handle:
        data_list = [name, color]
        if program(data_list) == 0:
            exit()

